import { http } from '../http';
import type { ApiResponse } from '~/api/types/http';
import type {
  Message,
  SendMessageParams,
  MessageListResponse,
  MarkReadParams,
} from '~/api/types/message';

/**
 * 消息相关API组合函数
 */
export const useMessageApi = () => {
  /**
   * 获取消息列表
   * @param consultId 咨询ID
   * @returns useFetch 响应对象，包含 data、pending、error 等
   */
  const getMessageList = (consultId: string) =>
    http.get<MessageListResponse>(`/message/list/${consultId}`);

  /**
   * 发送消息
   * @param params 消息参数
   * @returns useFetch 响应对象
   */
  const sendMessage = (params: SendMessageParams) =>
    http.post<Message>('/message/send', params);

  /**
   * 获取消息详情
   * @param messageId 消息ID
   * @returns useFetch 响应对象
   */
  const getMessageDetail = (messageId: string) =>
    http.get<Message>(`/message/${messageId}`);

  /**
   * 标记消息为已读
   * @param messageId 消息ID
   * @returns useFetch 响应对象
   */
  const markMessageRead = (messageId: string) =>
    http.put(`/message/${messageId}/read`);

  /**
   * 批量标记消息为已读
   * @param params 消息ID列表
   * @returns useFetch 响应对象
   */
  const markMessagesRead = (params: MarkReadParams) =>
    http.put('/message/batch-read', params);

  return {
    getMessageList,
    sendMessage,
    getMessageDetail,
    markMessageRead,
    markMessagesRead,
  };
};
